<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分配页面</title>
    <link rel="stylesheet" href="../public/layui/css/layui.css"  media="all">
    <style>
        .layui-table,.layui-table-view{
            margin: 0 0px;
        }
    </style>

</head>
<body>

<!-- 表单 -->
<table class="layui-hide" id="cardTable" lay-filter="formFilter"></table>
<script src="../public/layui/layui.js" charset="utf-8"></script>

<!-- 表格后面的操作 -->
<script type="text/html" id="operateBar">
    <a class="layui-btn layui-btn-xs" lay-event="assign">分配订单</a>
</script>
<script>
    layui.use(['table','jquery'], function(){
        $ = layui.jquery;
        var table = layui.table;
        // 进行渲染
        var tableIns =  table.render({
            elem: '#cardTable'
            ,url:'./postmanList'
            ,toolbar: '#headBar'
            ,height: 600
            ,cols: [[
                {type: 'numbers', width:50, fixed:'left'}
                ,{field: 'name', title: '快递员姓名', width:180, sort: true, fixed: 'left'}
                ,{field: 'area', title: '管辖区域', width:170, sort: true}
                ,{field: 'phonenumber', title: '联系方式', width: 140, sort: true}
                ,{fixed: 'right', title:'操作', width: 200, align:'center', toolbar: '#operateBar'} //这里的toolbar值是模板元素的选择器
            ]]
        });

        // 头部工具栏事件


        // 侧边工具栏事件
        table.on(('tool(formFilter)'), function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            var id = data.id;
            var oid = data.oid;
            switch(obj.event){
                case 'assign':
                    layer.confirm('是否分配', function(index){
                        layer.close(index);
                        $.ajax({
                            url: './orderassign',
                            method: 'get',
                            dataType: 'JSON',
                            data: "id=" +id+"&oid="+<%=request.getParameter("oid")%>,
                            success: function(data){
                                if(data.code == 0){
                                    layer.msg(data.msg);
                                    $('.layui-laypage-btn').click();
                                }else{
                                    layer.msg(data.msg);
                                }

                            }
                        })
                    });
                    break;
            }
        })
    });
</script>
</body>
</html>